<template>
	<view class="pagesBox">
		<view class="pagesMain">
			<view class="jifenBox">
				<view class="jifenTop">
					<view class="jifenTitle">总积分</view>
					<view class="jifenNum">{{fmtPrice(scoreInfo.score_all)}}</view>
				</view>
				<view class="lineBox"></view>
				<view class="jifenBottom">
					<view class="jifenItem">
						<view class="jifenNum">{{fmtPrice(scoreInfo.score_m)}}</view>
						<view class="jifenTitle">本月积分</view>
					</view>
					<view class="jifenItem">
						<view class="jifenNum">{{fmtPrice(scoreInfo.score_settle)}}</view>
						<view class="jifenTitle">已结算积分</view>
					</view>
					<view class="jifenItem">
						<view class="jifenNum">{{fmtPrice(scoreInfo.score_d)}}</view>
						<view class="jifenTitle">今日获得积分</view>
					</view>
				</view>
			</view>
			<view class="recordBox">
				<view class="recordBg"></view>
				<view class="recordTypeBox">
					<view class="toggleBg">
						<view class="iamgeBox">
							<image src="/static/my/icon19.png" style="width: 36rpx;height: 36rpx;"></image>
						</view>
						<view>{{params.month}}月 每日积分</view>
					</view>
					<picker @change="changeTime" style="width: 50%;" mode="date" :value="params.month" start="2000-01" :end="nowTime" fields="month">
						<view class="toggleBg toggleItem1" style="width: 100%;">
							<view class="iamgeBox">
								<image src="/static/my/icon18.png" style="width: 36rpx;height: 36rpx;"></image>
							</view>
							<view>其他月份</view>
						</view>
					</picker>
					<!-- <view class="toggleBg toggleItem1">
						<view class="iamgeBox">
							<image src="/static/my/icon18.png" style="width: 36rpx;height: 36rpx;"></image>
						</view>
						<view>其他月份</view>
					</view> -->
				</view>
				<view class="infoBox">
					<my-record :recordList="recordList" :total="total"></my-record>
				</view>
			</view>
		</view>
		<!-- <u-picker mode="time" v-model="showTime" :params="paramsTime" :default-time="defaultTime" confirm-color="#2BA777"></u-picker> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl:this.$baseUrl,
				scoreInfo:{},
				recordList:[],
				total:-1,
				statusType:'more',
				params:{
					month:"",
					limit:15,
					page:1
				},
				showTime:false,
				paramsTime: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
				nowTime:""
			};
		},
		onLoad(options) {
			this.getScoreInfo()
			this.getRecord();
			this.getNowTime();
		},
		methods:{
			async getScoreInfo(){
				let res = await uni.$http('POST','score/index');
				console.log("积分信息",res);
				if(res.code == 1){
					this.scoreInfo = res.data;
				}else if(res.msg.includes('登录')){
					uni.setStorageSync('token',0);
				}
			},
			async getRecord(){
				let res = await uni.$http('POST','score/record',this.params);
				if(res.code == 1){
					this.params.page = res.data.current_page;
					this.total = res.data.total;
					if(this.params.page == 1){
						this.recordList = res.data.data;
					}else{
						this.recordList = this.recordList.concat(res.data.data);
					}
					if(this.recordList.length < this.total){
						this.statusType = 'more'
					}else{
						this.statusType = 'noMore'
					}
				}else if(res.msg.includes('登录')){
					this.total = 0;
					uni.removeStorageSync("token")
				}else{
					this.total = 0;
				}
			},
			getNowTime(){
				let date = new Date();
				let y = date.getFullYear();
				let m = date.getMonth() + 1;
				m = m < 10 ? ('0' + m) : m;
				this.nowTime = y + '-' + m;
				this.params.month = y + '-' + m;
			},
			changeTime(e){
				console.log(e);
				this.params.page = 1;
				this.params.month = e.detail.value;
				this.getRecord()
			},
			// 格式化价钱
			fmtPrice(price1 = 0){
				return parseFloat(price1*1).toFixed(2)
			},
		},
		onReachBottom() {
			if(this.recordList.length < this.total){
				this.statusType = 'loading';
				this.params.page++;
				this.getRecord()
			}else{
				this.statusType = 'noMore'
			}
		}
	}
</script>

<style scoped lang="scss">
.pagesBox{
	.pagesMain{
		.jifenBox{
			height: 320rpx;
			color: #fff;
			background-color: #2BA777;
			display: flex;
			flex-direction: column;
			justify-content: space-evenly;
			align-items: center;
			.jifenTop{
				width: 100%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.jifenTitle{
					font-size: 24rpx;
					letter-spacing: 2rpx;
				}
				.jifenNum{
					font-size: 60rpx;
					margin-top: 6rpx;
				}
			}
			.lineBox{
				width: 60rpx;
				height: 2rpx;
				background-color: #fff;
			}
			.jifenBottom{
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				.jifenItem{
					width: 32%;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					.jifenTitle{
						color: #f9f9f9;
						font-size: 20rpx;
						margin-top: 6rpx;
						letter-spacing: 2rpx;
					}
					.jifenNum{
						font-size: 42rpx;
					}
				}
			}
		}
		.recordBox{
			padding: 0 24rpx;
			padding-top: 36rpx;
			position: relative;
			.recordBg{
				height: 160rpx;
				background-color: #2BA777;
				position: absolute;
				top: 0%;
				left: 0%;
				right: 0%;
			}
			.recordTypeBox{
				font-size: 28rpx;
				background-color: #FFFFFF;
				border-radius: 16rpx 16rpx 0 0;
				overflow: hidden;
				display: flex;
				align-items: center;
				position: relative;
				.toggleBg{
					width: 50%;
					height: 86rpx;
					text-align: center;
					font-weight: 600;
					color: #2BA777;
					background-color: #FFFFFF;
					border-radius: 16rpx 0 0 0;
					display: flex;
					justify-content: center;
					align-items: center;
					.iamgeBox{
						font-size: 0%;
						margin-right: 12rpx;
					}
				}
				.toggleItem1{
					font-weight: 500;
					color: #9a9a9a;
					background-color: #eaeaeb;
					border-radius: 0 16rpx 0 16rpx;
				}
			}
			.infoBox{
				background-color: #FFFFFF;
				border-radius: 0rpx 0rpx 16rpx 16rpx;
				position: relative;
			}
		}
	}
}
</style>
<style>
	page{
		background-color: #F7F8FA;
	}
</style>
